﻿using System;
using System.Data.Entity.ModelConfiguration;
using Dino.EntityFramework;

namespace Tests.Dino.EntityFramework
{
    public class TestContext : ObjectContext
    {
        public TestContext()
        {
        }

        public TestContext(Func<Type, bool> isTypeRegistered, Func<Type, object> resolve)
            : base(isTypeRegistered, resolve)
        {
        }

        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new EntityConfiguration());
            modelBuilder.Configurations.Add(new SomeEntityConfiguration());
//            modelBuilder.Entity<SomeEntity>().HasKey(e => e.Id).HasMany(e => e.SomeCollection);
            base.OnModelCreating(modelBuilder);
        }
    }

    public class EntityConfiguration : EntityTypeConfiguration<Entity>
    {
        public EntityConfiguration()
        {
            ToTable("Entity");

            HasKey(e => e.Id);
            Property(e => e.Foo);
        }
    }

    public class SomeEntityConfiguration : EntityTypeConfiguration<SomeEntity>
    {
        public SomeEntityConfiguration()
        {
            ToTable("SomeEntity");

            HasKey(e => e.Id);
            HasMany(e => e.SomeCollection);
            Ignore(e => e.Entity);
        }
    }
}
